<!DOCTYPE html>
<html>
<head>
  <title>Load SHP overlay</title>
  <link rel="stylesheet" href="https://openlayers.org/en/v6.3.1/css/ol.css" type="text/css">
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
  <script src="https://openlayers.org/en/v6.3.1/build/ol.js"></script>
  <script src="https://gipong.github.io/shp2geojson.js/lib/jszip.js"></script>
  <script src="https://gipong.github.io/shp2geojson.js/lib/jszip-utils.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.1/proj4.js"></script>
  <script src="https://gipong.github.io/shp2geojson.js/preprocess.js"></script>
  <script src="https://gipong.github.io/shp2geojson.js/preview.js"></script>
  <style>
    html, body, .map {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
    }
  </style>
</head>
<body>
<div id="map" class="map"></div>
<script>

  const featureStyle = new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: 'red',
      width: 1
    })
  });

  const map = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    target: 'map',
    view: new ol.View({
      center: [0, 0],
      zoom: 2
    })
  });

  map.getViewport().addEventListener('dragover', function(event) {
    event.preventDefault();
  });

  map.getViewport().addEventListener('drop', function(event) {
    event.preventDefault();
    const files = event.dataTransfer.files;
    for (let i = 0, ii = files.length; i < ii; ++i) {
      const file = files.item(i);
      loadshp({url: file, encoding: 'utf-8'}, function(geojson) {
        const features = new ol.format.GeoJSON().readFeatures(
                geojson,
                { featureProjection: map.getView().getProjection() }
        );
        const vectorSource = new ol.source.Vector({
          features: features
        });
        map.addLayer(
                new ol.layer.Vector({
                  source: vectorSource,
                  style: featureStyle
                })
        );
        map.getView().fit(vectorSource.getExtent());
      });
    }
  });

</script>
</body>
</html>